package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.Trends;
import com.zutassociation.system.service.TrendsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动态 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/4/20 21:13
 */
@RestController
@RequestMapping("/trends")
public class TrendsController extends BaseController {

    @Autowired
    private TrendsService trendsService;

    /**
     * 获取动态列表
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:list')")
    @GetMapping("/list")
    public TableDataInfo list(Trends trends) {
        startPage();
        List<Trends> list = trendsService.selectTrendsList(trends);
        return getDataTable(list);
    }

    /**
     * 根据发送人动态编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:query')")
    @GetMapping(value = "/userId/{userId}")
    public AjaxResult getFromInfo(@PathVariable("userId") Long userId) {
        return AjaxResult.success(trendsService.selectTrendsByUserId(userId));
    }

    /**
     * 根据动态编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:query')")
    @GetMapping(value = "/{trendsId}")
    public AjaxResult getInfo(@PathVariable("trendsId") Long trendsId) {
        return AjaxResult.success(trendsService.selectTrendsById(trendsId));
    }

    /**
     * 新增动态
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Trends trends) {
        trends.setCreateBy(SecurityUtils.getUsername());
        return toAjax(trendsService.insertTrends(trends));
    }

    /**
     * 修改动态
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Trends trends) {
        trends.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(trendsService.updateTrends(trends));
    }

    /**
     * 修改动态状态
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@Validated @RequestBody Trends trends) {
        trends.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(trendsService.updateTrendsStatus(trends));
    }

    /**
     * 修改动态举报状态
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateReport")
    public AjaxResult updateReport(@Validated @RequestBody Trends trends) {
        trends.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(trendsService.updateTrendsReport(trends));
    }


    /**
     * 浏览量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateClick")
    public AjaxResult updateClick(@Validated @RequestBody Trends trends) {
        return toAjax(trendsService.updateTrendsClick(trends));
    }
    /**
     * 点赞量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateFabulous")
    public AjaxResult updateFabulous(@Validated @RequestBody Trends trends) {
        return toAjax(trendsService.updateTrendsFabulous(trends));
    }

    /**
     * 收藏量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateCollection")
    public AjaxResult updateCollection(@Validated @RequestBody Trends trends) {
        return toAjax(trendsService.updateTrendsCollection(trends));
    }
    /**
     * 回复量+1
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:edit')")
    @PutMapping("/updateReply")
    public AjaxResult updateReply(@Validated @RequestBody Trends trends) {
        return toAjax(trendsService.updateTrendsReply(trends));
    }
    @PutMapping("/updateReplyDel")
    public AjaxResult updateReplyDel(@Validated @RequestBody Trends trends) {
        return toAjax(trendsService.updateTrendsReplydel(trends));
    }

    /**
     * 删除动态
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:remove')")
    @DeleteMapping("/{trendsIds}")
    public AjaxResult remove(@PathVariable Long[] trendsIds) {
        return toAjax(trendsService.deleteTrendsByIds(trendsIds));
    }

    /**
     * 批量修改动态举报状态为 1 成功
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:remove')")
    @DeleteMapping("/delReport1/{trendsIds}")
    public AjaxResult deleteReport1(@PathVariable Long[] trendsIds) {
        return toAjax(trendsService.deleteTrendsByReport1(trendsIds));
    }

    /**
     * 批量修改动态举报状态为 2 不成功
     */
//    @PreAuthorize("@ss.hasPermi('system:trends:remove')")
    @DeleteMapping("/delReport2/{trendsIds}")
    public AjaxResult deleteReport2(@PathVariable Long[] trendsIds) {
        return toAjax(trendsService.deleteTrendsByReport2(trendsIds));
    }

}
